import type { AddressItem, AddressParams } from '@/types/address'
import http from '@/utils/http'

/**
 * 新增会员地址
 * @param data 地址表单
 */
export const postMemberAddressAPI = (data: AddressParams) => {
  return http<{
    id: number
  }>({
    method: 'POST',
    url: '/member/address',
    data
  })
}

/**
 * 获取会员收货地址列表
 */
export const getMemberAddressAPI = () => {
  return http<AddressItem[]>({
    method: 'GET',
    url: '/member/address',
  })
}

/**
 * 获取会员地址详情
 * @param id 地址id
 */
export const getMemberAddressDetailAPI = (id: string) => {
  return http<AddressItem>({
    method: 'GET',
    url: `/member/address/${id}`,
  })
}

/**
 * 修改地址
 * @param id 地址id
 * @param data 地址表单
 */
export const putMemberAddressAPI = (id: string, data: AddressParams) => {
  return http<{
    id: string
  }>({
    method: 'PUT',
    url: `/member/address/${id}`,
    data
  })
}


/**
 * 删除会员地址
 * @param id 地址id
 */
export const deleteMemberAddressAPI = (id: string) => {
  return http<{
    id: string
  }>({
    method: 'DELETE',
    url: `/member/address/${id}`,
  })
}
